package com.zk.mockito.cases;

import org.junit.Test;
import org.mockito.ArgumentCaptor;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

/**
 *  捕获mock方法参数的方法。
 */
public class Case015_CapturingArgumentsForFurtherAssertions {

    /**
     * Capturing Arguments For Further Assertions
     * 该Capture模式可以应用到对匿名函数式代码段的捕获，然后执行该代码段提升代码覆盖率和验证范围
     */
    @Test
    public void testCapturingArgumentsForFurtherAssertions() {
        ArgumentCaptor<Person> argument = ArgumentCaptor.forClass(Person.class);
        Mocked mock = mock(Mocked.class);
        mock.doSomething(new Person());
        verify(mock).doSomething(argument.capture());
        // capture 捕获的是真实传递的参数
        assertEquals("John", argument.getValue().getName());
    }

}
